package cliente;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientSocket {
	
    private PrintStream saida;
    private BufferedReader entrada;
	private Socket conexao;
	
	ClientSocket(String host) throws UnknownHostException, IOException{
		conectar(host);
	}
	
	private void prepararPassagemDeDados(Socket conexao) throws IOException{
		this.saida = new PrintStream(conexao.getOutputStream());
		this.entrada = new BufferedReader(new InputStreamReader(conexao.getInputStream()));
	}
	
	public void conectar(String host) throws UnknownHostException, IOException{
		conexao = new Socket(host, 7001);
		prepararPassagemDeDados(conexao);
	}
	
	public void enviar(String mensagem){
		saida.println(mensagem);
	}
	
	public String receber() throws IOException{
	 	return entrada.readLine();
	}
}

